class_name XPButton
extends Button

# ===============================================

@export var player_stats: PlayerStats
@export var sfx: AudioStream
@export var gold_cost: int = 4
@export var xp_provided: int = 4

# ===============================================

@onready var v_box_container: VBoxContainer = $VBoxContainer

# ===============================================

func __on_player_stats_changed() -> void:
	disabled = player_stats.gold < gold_cost or player_stats.level == player_stats.MAX_LEVEL
	if disabled:
		v_box_container.modulate.a = 0.5
	else:
		v_box_container.modulate.a = 1.0

# ===============================================

func _ready() -> void:
	player_stats.changed.connect(__on_player_stats_changed)
	__on_player_stats_changed()


func _on_pressed() -> void:
	player_stats.gold -= gold_cost
	player_stats.xp += xp_provided
	SFXPlayer.play(sfx)
